package com.hockeo.client.ui.base.tree;

import java.util.List;

import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.DataReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * Special {@link BeanModelReader} to be used by the VHTree. It was necessary to implement
 * this special reader as the default TreeLoader expects the parameter of the
 * {@link AsyncCallback#onSuccess(Object)} method to be a list, but BeanModelReader
 * returns a {@link ListLoadResult}.
 *
 * @version $Id$
 * @author jjanke
 */
public class VHTreeBeanModelReader implements DataReader<List<ModelData>>
{
  private BeanModelReader d_wrappedReader = new BeanModelReader();

  /**
   * Return if a BeanModelFactory is created for each bean or not.
   *
   * @return true if a BeanModelFactory is created for each bean or not
   */
  public boolean isFactoryForEachBean()
  {
    return d_wrappedReader.isFactoryForEachBean();
  }

  public List<ModelData> read( Object loadConfig, Object data )
  {
    return d_wrappedReader.read( loadConfig, data ).getData();
  }

  /**
   * Set to true to create a BeanModelFactory for each bean in the list (defaults to
   * false).
   *
   * @param d_fFactoryForEachBean true to enable
   */
  public void setFactoryForEachBean( boolean flag )
  {
    d_wrappedReader.setFactoryForEachBean( flag );
  }
}
